using System;
using PCE.Data;
using PCE.Data.Queries;
using PCE.Domain;

namespace PCE.Core
{
	public class CustomerRegistrator : ICustomerRegistrator
	{
		private readonly IRepository<Customer, int> _customerRepository;

		public CustomerRegistrator(IRepository<Customer, int> customerRepository)
		{
			_customerRepository = customerRepository;
		}

		public bool CheckExistance(string login, string email)
		{
			return _customerRepository.Count(CustomerSpecs.WithIdentity(login, email)) == 0;
		}

		public Customer Register(string login, string email, string password)
		{
			var customer = new Customer
			{
				Login = login,
				Email = email,
				Password = password
			};
			
			_customerRepository.Save(customer);

			return customer;
		}
	}
}